
import CompanyAPI from '../api/company.js';

export const Company={
   state:{
      companylist:[],
      company_total_count:0,
      editCompanyStatus:-1,     //插入状态 0失败  1成功  -1不改变
      companyinfo:[],
      delCompanyStatus:-1,       //删除状态
      allcompanytype:[
         {label:'集体企业',value:'1'},
         {label:'外资企业',value:'2'},
         {label:'私营企业',value:'3'},
         {label:'行政事业单位',value:'4'},
         {label:'个体户',value:'5'},
         {label:'其他企业',value:'6'}
      ]
   },
   mutations:{
      setCompanyList(state,list){
          state.companylist=list;
      },
      setCompanyTotalCount(state,total_count){
          state.company_total_count=total_count;
      },
      setEditCompanyStatus(state,status){
          state.editCompanyStatus=status;
      },
      setCompanyInfo(state,info){
          state.companyinfo=info;
      },
      setDelCompanyStatus(state,status){
          state.delCompanyStatus=status;
      }
   },
   actions:{
      loadCompanyList(context,data){
          CompanyAPI.getCompanyList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCompanyList',response.data.list);
                  context.commit('setCompanyTotalCount',response.data.total_count);
              }
          })
      },
      //插入Company
      editCompany(context,data){
          CompanyAPI.editCompany(data).then(function(response){
              context.commit('setEditCompanyStatus',response.data.code);
          })
      },
      //获取详情
      loadCompanyInfo(context,data){
          CompanyAPI.getCompanyInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCompanyInfo',response.data.info);
              }
          })
      },
      //删除
      delCompany(context,data){
          CompanyAPI.delCompany(data).then(function(response){
                context.commit('setDelCompanyStatus',response.data.code);
          })
      }
   },
   getters:{
      getCompanyList:state =>{
         return state.companylist
      },
      getCompanyTotalCount: state =>{
         return state.company_total_count
      },
      getEditCompanyStatus:state=>{
          return state.editCompanyStatus;
      },
      getCompanyInfo:state => {
          return state.companyinfo;
      },
      getDelCompanyStatus:state => {
          return state.delCompanyStatus;
      },
      getAllCompanyType:state=>{
          return state.allcompanytype;
      }
   }
}
